package com.junmoo.www.config.mqtt;//package com.junmo.emqx.mqtt;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

@RestController
@RequestMapping("/mqtt")
public class MqttController {
    @Autowired
    MqttGateway mqttGateway;

    @GetMapping(value = "test")
    public Mono<String> test() {
        return Mono.just("success");
    }
    @PostMapping(value = "s1")
    public Mono<String> sendMsg(String message) {
        mqttGateway.sendToMqtt("s2", "defualt-topic:" + message);
        return Mono.just("success");
    }

    @PostMapping(value = "/s2")
    public Mono<String> sendMsg2(String topic, String message) {
        mqttGateway.sendToMqtt(topic, "消息内容 : " + message);
        return Mono.just("success");
    }
}
